<?php
include_once '../include/lxbase.class.php';
if(!empty($_GET["code"])){
	$webconn = new Lxbase();
	$code=$_GET["code"];
	$state=$_GET["state"];
	if(empty($state) || empty($code)){die("获取关键参数失败");}
	$data = json_decode(base64_decode($_GET["state"]),true);
	$url='https://api.weixin.qq.com/sns/oauth2/access_token?code='.$code.'&grant_type=authorization_code&appid='.$data["appid"].'&secret='.$data["secret"];
	$rs = $webconn->call_get($url);
	$ret=json_decode($rs,true);
	if(!empty($ret["openid"])){
		$data["openid"]=$ret["openid"];
		$wxpaydata=base64_encode(json_encode($data));
		header("location:wxpay.php?wxpaydata={$wxpaydata}");
		exit;
	}else{
		die($ret["errmsg"]);
	}
	
}